package org.example.ffmmx.bmapandroid;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.*;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.model.LatLngBounds;
import com.baidu.mapapi.utils.DistanceUtil;
import org.example.ffmmx.bmapandroid.model.AlarmArea;
import org.example.ffmmx.bmapandroid.model.DemoAboutMenu;

import java.util.ArrayList;
import java.util.List;


public class DemoMainActivity extends ActionBarActivity {
    private List<AlarmArea> alarmAreas;
    private ListView markerManageListView;
    private TextureMapView baiduMapView;
    private BaiduMap baiduMap;
    private TabHost tabHost;
    private List<DemoAboutMenu> demoAboutMenus;
    private ListView aboutMenuListView;
    private List<Overlay> afterRenerOverlays;
    private int markerLength = 0;
    private DemoTabOption[] tabOptions = new DemoTabOption[]{
            new DemoTabOption("alarmAreaMap", "地图", R.id.bMapLayout),
            new DemoTabOption("markerManage", "标记管理", R.id.manageMarkerLayout),
            new DemoTabOption("abountMe", "我", R.id.aboutMeLayout)
    };

    private List<AlarmArea> selectedAlarmAreas;
    private LocationClient mLocClient, targetLocClient;
    private boolean isFirstLoc = true;
    private LinearLayout alarmAreaDeletePanel;
    private boolean isMutiSelect = false;
    private SeekBar radiusSeekBar;
    private CircleOptions defaultCircleOptions = new CircleOptions().fillColor(Color.argb(70, 0, 255, 255)).radius(100);
    NotificationManager notificationManager;
    private String NOTIFICATION_INAREA_TEMPLATE="{name}进入监视范围{area_title}";
    private String NOTIFICATION_OUTAREA_TEMPLATE="{name}脱离监视范围{area_title}";

    public DemoMainActivity() {
        alarmAreas = new ArrayList<>();
        demoAboutMenus = new ArrayList<>();
        afterRenerOverlays = new ArrayList<>();
        selectedAlarmAreas = new ArrayList<>();
    }

    /**
     * 在地图上创建标记
     */
    public void createMarkerOnMap(LatLng location) {
        View markerView = getLayoutInflater().inflate(R.layout.marker, null);
        TextView markerTitle = (TextView) markerView.findViewById(R.id.markerTitle);
        markerTitle.setText("" + (alarmAreas.size() + 1));
        BitmapDescriptor icon = BitmapDescriptorFactory.fromView(markerView);
        OverlayOptions markerOptions = new MarkerOptions().position(location).icon(icon);
        afterRenerOverlays.add(baiduMap.addOverlay(markerOptions));
    }

    /**
     * 清除未完成的标记和范围
     */
    public void unDoneMarkerClear() {
        if (afterRenerOverlays.size() > 0 && alarmAreas.size() * 2 < afterRenerOverlays.size()) {
            List<Overlay> deleteOverlays = new ArrayList<>();
            for (int i = alarmAreas.size() * 2; i < afterRenerOverlays.size(); i++) {
                Overlay overlay = afterRenerOverlays.get(i);
                if (overlay instanceof Marker || overlay instanceof Circle) {
                    deleteOverlays.add(overlay);
                    overlay.remove();
                }
            }

            afterRenerOverlays.removeAll(deleteOverlays);
        }
    }

    /**
     * 清除未完成的范围
     */
    public void unDoneCircleClear() {
        if (afterRenerOverlays.size() > 0 && alarmAreas.size() * 2 < afterRenerOverlays.size()) {
            List<Overlay> deleteOverlays = new ArrayList<>();
            for (int i = alarmAreas.size() * 2; i < afterRenerOverlays.size(); i++) {
                Overlay overlay = afterRenerOverlays.get(i);
                if (overlay instanceof Circle) {
                    deleteOverlays.add(overlay);
                    overlay.remove();
                }
            }
            afterRenerOverlays.removeAll(deleteOverlays);
        }
    }

    /**
     * 渲染选择的警报区域
     */
    public void renderAlarmAreas() {
        baiduMap.clear();
        afterRenerOverlays.clear();
        markerLength = 0;
        for (AlarmArea alarmArea : alarmAreas) {
            if ("Y".equals(alarmArea.getUseStatus())) {
                View markerView = getLayoutInflater().inflate(R.layout.marker, null);
                TextView markerLabel = ((TextView) markerView.findViewById(R.id.markerTitle));
                markerLabel.setText(++markerLength + "");
                LatLng position = new LatLng(alarmArea.getPointLatitude(), alarmArea.getPointLongitude());
                MarkerOptions markerOptions = new MarkerOptions().position(position)
                        .icon(BitmapDescriptorFactory.fromView(markerView)).title(alarmArea.getTitle());
                CircleOptions circleOptions = new CircleOptions().center(position).radius(alarmArea.getRadius()).fillColor(defaultCircleOptions.getFillColor());
                Overlay marker = baiduMap.addOverlay(markerOptions);
                Bundle bundle = new Bundle();
                bundle.putInt("radius", alarmArea.getRadius());
                marker.setExtraInfo(bundle);

                afterRenerOverlays.add(marker);
                afterRenerOverlays.add(baiduMap.addOverlay(circleOptions));


            }
        }
    }

    /**
     * 缩放地图，使所有Overlay都在合适的视野内
     * <p>
     * 注： 该方法只对Marker类型的overlay有效
     * </p>
     */
    private void zoomToSpan() {
        if (baiduMap == null) {
            return;
        }
        if (afterRenerOverlays.size() > 0) {
            LatLngBounds.Builder builder = new LatLngBounds.Builder();
            for (Overlay overlay : afterRenerOverlays) {
                // polyline 中的点可能太多，只按marker 缩放
                if (overlay instanceof Marker) {
                    builder.include(((Marker) overlay).getPosition());
                }
            }
            baiduMap.setMapStatus(MapStatusUpdateFactory
                    .newLatLngBounds(builder.build()));
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo_main);

        tabHost = (TabHost) findViewById(R.id.demoTabHost);
        baiduMapView = (TextureMapView) findViewById(R.id.demoBaiduMapView);
        radiusSeekBar = (SeekBar) findViewById(R.id.radiusSeekBar);

        initData(); //初始化数据

        tabHost.setup();
        for (DemoTabOption tabOption : tabOptions) {
            tabHost.addTab(tabHost.newTabSpec(tabOption.tag).setIndicator(tabOption.indictor).setContent(tabOption.contentId));
        }
        baiduMapView.showScaleControl(false);
        baiduMapView.showZoomControls(true);
        baiduMapView.removeViewAt(1); //去掉百度logo

        ListViewItemClickListener listViewItemClickListener = new ListViewItemClickListener();
        final ButtonOnClickListener buttonOnClickListener = new ButtonOnClickListener();
        ListViewLongClickListener listViewLongClickListener = new ListViewLongClickListener();

        baiduMap = baiduMapView.getMap();
//        点击地图弹出标记
        baiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                unDoneMarkerClear();
                baiduMap.hideInfoWindow();
                createMarkerOnMap(latLng);
            }

            @Override
            public boolean onMapPoiClick(MapPoi mapPoi) {
                unDoneMarkerClear();
                baiduMap.hideInfoWindow();
                createMarkerOnMap(mapPoi.getPosition());
                return false;
            }
        });

//        点击标记弹出菜单
        baiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                //创建InfoWindow展示的view
                View markerPopView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.marker_pop, null);
                markerPopView.setTag(marker);
                Button markerBtn = (Button) markerPopView.findViewById(R.id.markerInfoWEnterBtn);
                Button cancelBtn = (Button) markerPopView.findViewById(R.id.markerInfoWCancelBtn);
                markerBtn.setOnClickListener(buttonOnClickListener);
                cancelBtn.setOnClickListener(buttonOnClickListener);
                radiusSeekBar.setTag(marker);

                radiusSeekBar.setVisibility(View.VISIBLE);
                if (marker.getExtraInfo() != null) {
                    radiusSeekBar.setProgress(marker.getExtraInfo().getInt("radius", defaultCircleOptions.getRadius()));
                }

//定义用于显示该InfoWindow的坐标点
//创建InfoWindow , 传入 view， 地理坐标， y 轴偏移量
                InfoWindow mInfoWindow = new InfoWindow(markerPopView, marker.getPosition(), -60);
//显示InfoWindow
                baiduMap.showInfoWindow(mInfoWindow);
                return false;
            }
        });

        radiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (seekBar.getId() == R.id.radiusSeekBar) {
                    unDoneCircleClear();
                    Marker marker = (Marker) seekBar.getTag();
                    Circle existCc=null;
                    for (Overlay overlay : afterRenerOverlays) {
                        if(overlay instanceof Circle){
                            Circle cc= ((Circle) overlay);
                            if (cc.getCenter().latitude == marker.getPosition().latitude && cc.getCenter().longitude == marker.getPosition().longitude){
                                existCc=cc;
                                break;
                            }
                        }
                    }
                    if (existCc != null) {
                        existCc.setRadius(progress);
                    }
                    else {
                        CircleOptions circleOptions = new CircleOptions().radius(progress).fillColor(defaultCircleOptions.getFillColor())
                                .center(marker.getPosition());
                        afterRenerOverlays.add(baiduMap.addOverlay(circleOptions));
                    }
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Marker marker = (Marker) seekBar.getTag();
                Bundle bu = marker.getExtraInfo();
                if (bu == null) {
                    bu = new Bundle();
                    marker.setExtraInfo(bu);
                }
                bu.putInt("radius", seekBar.getProgress());
            }
        });

        aboutMenuListView = (ListView) findViewById(R.id.aboutMenuListView);
        aboutMenuListView.setAdapter(new AboutMenuAdapter(demoAboutMenus, getLayoutInflater()));
        aboutMenuListView.setOnItemClickListener(listViewItemClickListener);

        markerManageListView = (ListView) findViewById(R.id.manageMarkerListView);
        markerManageListView.setAdapter(new AlarmAreaAdapter(alarmAreas, getLayoutInflater()));
        markerManageListView.setOnItemClickListener(listViewItemClickListener);
        markerManageListView.setOnItemLongClickListener(listViewLongClickListener);

        alarmAreaDeletePanel = (LinearLayout) findViewById(R.id.checkboxControllPanel);
        alarmAreaDeletePanel.setVisibility(View.GONE);
        findViewById(R.id.markerCheckboxCancelBtn).setOnClickListener(buttonOnClickListener);
        findViewById(R.id.markerCheckboxDeleteBtn).setOnClickListener(buttonOnClickListener);
        baiduMap.setMyLocationEnabled(true);
        mLocClient = new LocationClient(getApplicationContext());
        mLocClient.registerLocationListener(new MyLocationListenner());
        LocationClientOption locationClientOption = new LocationClientOption();
        locationClientOption.setOpenGps(true);
        locationClientOption.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        locationClientOption.setCoorType("bd09ll");
        locationClientOption.setScanSpan(2000);
        mLocClient.setLocOption(locationClientOption);
        mLocClient.start();


        renderAlarmAreas();
        zoomToSpan();
        radiusSeekBar.setVisibility(View.GONE);

        notificationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        baiduMapView.onDestroy();
        mLocClient.stop();
    }

    @Override
    protected void onPause() {
        super.onPause();
        baiduMapView.onPause();
        mLocClient.stop();
    }

    @Override
    protected void onResume() {
        super.onResume();
        baiduMapView.onResume();
        mLocClient.start();
    }

    public Notification createNotification(String title,String message, Intent intent) {
//        设置声音
//        notification.defaults |= Notification.DEFAULT_SOUND;
//        notification.sound=
        PendingIntent contentIntent= PendingIntent.getActivity(getApplicationContext(),0,intent,0);
        Notification notification = new Notification.Builder(getApplicationContext()).setTicker(title)
                .setContentText(message).setContentTitle(title).setContentIntent(contentIntent).build();
        return notification;
    }
    /**
     * 选择改变事件
     */
    private class CheckedChangeListener implements CompoundButton.OnCheckedChangeListener {
        private Object data;

        public CheckedChangeListener(Object data) {
            this.data = data;
        }

        @Override
        public void onCheckedChanged(CompoundButton view, boolean isChecked) {
            if (view.getId() == R.id.markerCheckbox) {
                AlarmArea area = (AlarmArea) data;
                if (isChecked) {
                    selectedAlarmAreas.add(area);
                } else {
                    selectedAlarmAreas.remove(area);
                }
                ((TextView) alarmAreaDeletePanel.findViewById(R.id.markerCheckboxSelectText)).setText("共选择了" + selectedAlarmAreas.size() + "项");
            } else if (view.getId() == R.id.useSwitch) {
                AlarmArea area = (AlarmArea) data;
                if (isChecked)
                    area.setUseStatus("Y");
                else
                    area.setUseStatus("N");

                renderAlarmAreas();
                zoomToSpan();
            }
        }
    }

    /**
     * 按钮点击事件
     */
    private class ButtonOnClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            if (v.getId() == R.id.markerCheckboxCancelBtn) {
                selectedAlarmAreas.clear();
                for (AlarmArea area : alarmAreas) {
                    area.setChecked(false);
                }
                clearCheckboxMode();
            } else if (v.getId() == R.id.markerCheckboxDeleteBtn) {
                alarmAreas.removeAll(selectedAlarmAreas);
                clearCheckboxMode();
                renderAlarmAreas();
                zoomToSpan();
            } else if (v.getId() == R.id.markerInfoWEnterBtn) { //标记弹出框确认按钮
                Marker marker = (Marker) ((View) v.getParent()).getTag();
                int radius = marker.getExtraInfo().getInt("radius");
                AlarmArea modifyArea=null;
                for (AlarmArea alarmArea : alarmAreas) {
                    if (marker.getPosition().latitude==alarmArea.getPointLatitude() && alarmArea.getPointLongitude() == marker.getPosition().longitude) {
                        modifyArea=alarmArea;
                        break;
                    }
                }
                if (modifyArea != null) {
                    modifyArea.setRadius(radius);
                }
                else{
                    AlarmArea area = new AlarmArea(marker.getPosition().latitude, marker.getPosition().longitude,
                            radius, marker.getTitle());
                    alarmAreas.add(area);
                }
                ((BaseAdapter) markerManageListView.getAdapter()).notifyDataSetChanged();
                radiusSeekBar.setVisibility(View.GONE);
                baiduMap.hideInfoWindow();

            } else if (v.getId() == R.id.markerInfoWCancelBtn) { //标记弹出框取消按钮
                Marker marker = (Marker) ((View) v.getParent()).getTag();
                unDoneMarkerClear();
                radiusSeekBar.setVisibility(View.GONE);
                baiduMap.hideInfoWindow();

            } else if (v.getId() == R.id.markerInfoWDeleteBtn) { //标记弹出框删除按钮
                Marker marker = (Marker) ((View) v.getParent()).getTag();
                unDoneMarkerClear();
                List<AlarmArea> deleteAlarmAreas = new ArrayList<>();
                for (AlarmArea alarmArea : alarmAreas) {
                    if (alarmArea.getPointLatitude() == marker.getPosition().latitude && alarmArea.getPointLongitude() == marker.getPosition().longitude) {
                        deleteAlarmAreas.add(alarmArea);
                    }
                }
                alarmAreas.removeAll(deleteAlarmAreas);
                List<Overlay> deleteOverlays = new ArrayList<>();
                for (Overlay overlay : afterRenerOverlays) {
                    Marker mk = overlay instanceof Marker ? ((Marker) overlay) : null;
                    Circle circle = overlay instanceof Circle ? ((Circle) overlay) : null;
                    if (mk != null && mk.getPosition().latitude == marker.getPosition().latitude && mk.getPosition().longitude == marker.getPosition().longitude) {
                        deleteOverlays.add(mk);
                        mk.remove();
                    }
                    if (circle != null && circle.getCenter().latitude == marker.getPosition().latitude && circle.getCenter().longitude == marker.getPosition().longitude) {
                        deleteOverlays.add(circle);
                        circle.remove();
                    }
                }

                afterRenerOverlays.removeAll(deleteOverlays);
                ((BaseAdapter) markerManageListView.getAdapter()).notifyDataSetChanged();
                radiusSeekBar.setVisibility(View.GONE);
                baiduMap.hideInfoWindow();
            }
        }

        public void clearCheckboxMode() {
            isMutiSelect = false;
            alarmAreaDeletePanel.setVisibility(View.GONE);
            ((BaseAdapter) markerManageListView.getAdapter()).notifyDataSetChanged();
        }
    }

    /**
     * 列表长按事件
     */
    private class ListViewLongClickListener implements AdapterView.OnItemLongClickListener {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (parent.getId() == R.id.manageMarkerListView) {
                isMutiSelect = true;
                selectedAlarmAreas.clear();
                AlarmArea area = (AlarmArea) parent.getItemAtPosition(position);
                alarmAreaDeletePanel.setVisibility(View.VISIBLE);
                area.setChecked(true);
                ((BaseAdapter) parent.getAdapter()).notifyDataSetChanged();
                return true;

            } else if (parent.getId() == R.id.aboutMenuListView) {
                return true;
            }
            return false;
        }
    }

    /**
     * 定位SDK监听函数
     */
    private class MyLocationListenner implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // map view 销毁后不在处理新接收的位置
            if (location == null || baiduMapView == null) {
                return;
            }
            MyLocationData locData = new MyLocationData.Builder()
                    .accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(100).latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();
            baiduMap.setMyLocationData(locData);

            if (isFirstLoc) {
                isFirstLoc = false;
                LatLng ll = new LatLng(location.getLatitude(),
                        location.getLongitude());
                MapStatus.Builder builder = new MapStatus.Builder();
                builder.target(ll).zoom(18.0f);
                baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
            }

//            报警区域通知警告
            alarmAreaNotification(location);
        }
    }

    public void alarmAreaNotification(BDLocation location){
        for (AlarmArea area : alarmAreas) {
            if (DistanceUtil.getDistance(new LatLng(location.getLatitude(),location.getLongitude()),
                    new LatLng(area.getPointLatitude(),area.getPointLongitude())) >= area.getRadius()) {
                area.setMyLocInArea(false);
                if (!area.isMyLocOutArea()) {
                    notificationManager.notify(9999,createNotification("报警区域",NOTIFICATION_OUTAREA_TEMPLATE.replaceAll("\\{name\\}","当前用户").
                            replaceAll("\\{area_title\\}","自定义"),new Intent(getApplicationContext(),DemoMainActivity.class)));
                    area.setMyLocOutArea(true);
                }
            }
            else{
                area.setMyLocOutArea(false);
                if (!area.isMyLocInArea()) {
                    notificationManager.notify(9999,createNotification("报警区域",NOTIFICATION_INAREA_TEMPLATE.replaceAll("\\{name\\}","当前用户").
                            replaceAll("\\{area_title\\}","自定义"),new Intent(getApplicationContext(),DemoMainActivity.class)));
                    area.setMyLocInArea(true);
                }
            }
        }
    }
    private class ListViewItemClickListener implements AdapterView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (R.id.manageMarkerListView == parent.getId()) { //标记管理列表点击
                AlarmArea alarmArea = (AlarmArea) parent.getItemAtPosition(position);
                if (!isMutiSelect) {
                    tabHost.setCurrentTab(0);
                    LatLng poi = new LatLng(alarmArea.getPointLatitude(), alarmArea.getPointLongitude());
                    MapStatus.Builder builder = new MapStatus.Builder();
                    builder.target(poi).zoom(18f);
                    baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
                } else {
                    alarmArea.setChecked(!alarmArea.isChecked());
                    ((BaseAdapter) parent.getAdapter()).notifyDataSetChanged();
                }

            } else if (R.id.aboutMenuListView == parent.getId()) { //关于菜单列表点击
                DemoAboutMenu demoAboutMenu = (DemoAboutMenu) parent.getItemAtPosition(position);

            }
        }
    }

    private class AlarmAreaViewHolder {
        TextView title,
                mapAddrDesc;
        Switch useSwitch;
        CheckBox checkbox;
    }

    private class AlarmAreaAdapter extends BaseAdapter {
        private List<org.example.ffmmx.bmapandroid.model.AlarmArea> aData;
        private LayoutInflater layoutInflater;

        public AlarmAreaAdapter(List<AlarmArea> aData, LayoutInflater layoutInflater) {
            this.aData = aData;
            this.layoutInflater = layoutInflater;
        }

        @Override
        public int getCount() {
            return aData.size();
        }

        @Override
        public Object getItem(int position) {
            return aData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            AlarmAreaViewHolder holder = null;

            final AlarmArea area = aData.get(position);
            if (convertView == null) {
                holder = new AlarmAreaViewHolder();
                View alarmAreaView = convertView = layoutInflater.inflate(R.layout.demo_main_markmanage_listview, null);
                holder.title = (TextView) alarmAreaView.findViewById(R.id.title);
                holder.mapAddrDesc = (TextView) alarmAreaView.findViewById(R.id.mapAddrDesc);
                holder.useSwitch = (Switch) alarmAreaView.findViewById(R.id.useSwitch);
                holder.checkbox = (CheckBox) alarmAreaView.findViewById(R.id.markerCheckbox);
                convertView.setTag(holder);
            } else {
                holder = (AlarmAreaViewHolder) convertView.getTag();
            }


            holder.title.setText(area.getTitle());
            holder.mapAddrDesc.setText(area.getMapAddressDescription());
            holder.useSwitch.setChecked("Y".equals(area.getUseStatus()) ? true : false);
            holder.checkbox.setChecked(area.isChecked());

            CheckedChangeListener checkedChangeListener = new CheckedChangeListener(area);

            holder.useSwitch.setOnCheckedChangeListener(checkedChangeListener);
            holder.checkbox.setOnCheckedChangeListener(checkedChangeListener);

            if (isMutiSelect) {
                holder.checkbox.setVisibility(View.VISIBLE);
            } else
                holder.checkbox.setVisibility(View.GONE);

            return convertView;
        }
    }


    private void initData() {
//        初始化报警区域数据
        alarmAreas.add(new AlarmArea(39.93923, 116.357428, 200, "测试1"));
        alarmAreas.add(new AlarmArea(39.91923, 116.327428, 300, "测试2"));
        alarmAreas.add(new AlarmArea(39.89923, 116.347428, 500, "测试3"));
//        alarmAreas.add(new AlarmArea(39.89923, 116.367428,800,"测试4"));
//        alarmAreas.add(new AlarmArea(39.91923, 116.387428,1300,"测试5"));

//        初始化关于菜单数据
        demoAboutMenus.add(new DemoAboutMenu("profile", R.drawable.gran + "", "婆婆"));
        demoAboutMenus.add(new DemoAboutMenu("alarmArea", R.drawable.icon_gcoding + "", "报警区域设置"));
        demoAboutMenus.add(new DemoAboutMenu("about", null, "关于"));
    }

    private class DemoTabOption {
        private String tag, indictor;
        private int contentId;

        public DemoTabOption(String tag, String indictor, int contentId) {
            this.tag = tag;
            this.indictor = indictor;
            this.contentId = contentId;
        }


    }

    private class AboutMenuViewHolder {
        ImageView icon;
        TextView itemName;
        ImageView descIcon;
        TextView description;
    }

    private class AboutMenuAdapter extends BaseAdapter {
        private List<DemoAboutMenu> data;
        private LayoutInflater inflater;

        public AboutMenuAdapter(List<DemoAboutMenu> data, LayoutInflater inflater) {
            this.data = data;
            this.inflater = inflater;
        }

        @Override
        public int getCount() {
            return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            AboutMenuViewHolder holder;

            if (convertView == null) {
                holder = new AboutMenuViewHolder();
                View aboutMeMenu = convertView = inflater.inflate(R.layout.demo_aboutme_listview, null);
                holder.icon = (ImageView) aboutMeMenu.findViewById(R.id.demoAboutMeIcon);
                holder.itemName = (TextView) aboutMeMenu.findViewById(R.id.demoAboutMeItemName);
                holder.descIcon = (ImageView) aboutMeMenu.findViewById(R.id.demoAboutMeDescIcon);
                holder.description = (TextView) aboutMeMenu.findViewById(R.id.demoAboutMeDesc);
                aboutMeMenu.setTag(holder);
            } else {
                holder = (AboutMenuViewHolder) convertView.getTag();
            }

            DemoAboutMenu menu = data.get(position);
            if (menu.getIconPath() != null && menu.getIconPath().length() > 0)
                holder.icon.setImageResource(Integer.parseInt(menu.getIconPath()));
            holder.itemName.setText(menu.getItemName());
            if (menu.getDescriptionIconPath() != null && menu.getDescriptionIconPath().length() > 0)
                holder.descIcon.setImageResource(Integer.parseInt(menu.getDescriptionIconPath()));
            holder.description.setText(menu.getDescription());

            return convertView;
        }
    }
}
